//
//  CSMACAInitiator.hpp
//  WiFiMACSim
//
//  Created by Christopher Kemsley on 4/1/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#ifndef WiFiMACSim_CSMACAVCSInitiator_hpp
#define WiFiMACSim_CSMACAVCSInitiator_hpp

#include "Node.hpp"
#include "Message.hpp"
#include "Medium.hpp"
#include "Message.hpp"
#include "Statistics.hpp"

SimNamespaceBegin



class	CSMACAVCSInitiator : public TransitionalStateMachineNode<CSMACAVCSInitiator>
{
public:
	
	enum {
		kStateIdle				=	0 ,
		
		kStateSendingRTS		=	100 ,
		kStateWaitCTSOrDifs		=	101 ,
		kStateSendingData		=	103 ,
		kStateWaitACKOrDifs		=	104 ,
		
		kStateVCSSawRTS			=	2 ,
		kStateVCSSawCTS			=	3
	} ;
	
	ID const	target ;
	
	UInteger	lambdaScalar ;
	Message*	message ;
	
	SlotTimer	timer ;
	
	static const UInteger	Infinity	=	((UInteger)(-1)) ;
	
	StateStat	statistics ;
	
	
	
	CSMACAVCSInitiator ( ID const & name , ID const & inTarget , UInteger inLambdaScalar = 1 ) ;
	virtual ~CSMACAVCSInitiator () ;
	
	
	
	
	
	
	void	run_idle			( Message * incoming , bool completed , bool isBusy ) ;
	
	void	run_vcs_saw			( Message * incoming , bool completed , bool isBusy ) ;
	
	
	void	run_sendingRTS		( Message * incoming , bool completed , bool isBusy ) ;
	void	run_waitCTS_difs	( Message * incoming , bool completed , bool isBusy ) ;
	void	run_sendingData		( Message * incoming , bool completed , bool isBusy ) ;
	void	run_waitACK_difs	( Message * incoming , bool completed , bool isBusy ) ;
	
	void	run_waitDifs		( Message * incoming , bool completed , bool isBusy ) ;
	
	
	// handles carrier-sensing logic (both direct and virtual)
	void	breakwayForVCS		( Message * incoming , bool completed , bool isBusy ) ;
	
} ;




SimNamespaceEnd
#endif
